﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;

namespace libSyllabus.Model
{
    /// <summary>
    /// Base class for all the entities.
    /// Contains event handlers for refreshing database.
    /// </summary>
    /// <remarks>
    /// Event handlers should not be directly accessible from child classes,
    /// indeed, only RaiseEvent mathods should be accessible.
    /// </remarks>
    public abstract class EntityBase : INotifyPropertyChanging, INotifyPropertyChanged
    {
        // Private handlers
        private PropertyChangingEventHandler m_propertyChanging;
        private PropertyChangedEventHandler m_propertyChanged;

        // Public wrappers, keeping O-O coding style
        public event PropertyChangingEventHandler PropertyChanging
        {
            add
            {
                m_propertyChanging += value;
            }
            remove
            {
                m_propertyChanging -= value;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                m_propertyChanged += value;
            }
            remove
            {
                m_propertyChanged -= value;
            }
        }

        // RaiseEvent Methods, available only in child classes
        protected void RaisePropertyChanging(String propertyName)
        {
            if (m_propertyChanging != null)
                m_propertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
        protected void RaisePropertyChanged(String propertyName)
        {
            if (m_propertyChanged != null)
                m_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
